#include "util.h"
#include <string>
namespace
{
	template<typename T>
	std::string toString(T t)
	{
		std::stringstream ss;
		ss<<t;
		return ss.str();
	}
	template<>
	std::string toString(float t)
	{
		int * temp = (int*)(&t);
		std::stringstream ss;
		ss<<"0"<<std::hex<<*temp<<"H";
		return ss.str();
	}
}
std::string util::ToString(int a)
{
	return toString<int>(a);
}
std::string util::ToString(char a)
{
	return toString<int>(a);
}
std::string util::ToString(float a)
{
	return toString<float>(a);
}


std::stack<IDisposable *> IDisposable::s_garbarges;

void IDisposable::gc(IDisposable* g)
{
	s_garbarges.push(g);
}

void IDisposable::disposeALL()
{
	while(!s_garbarges.empty())
	{
		delete s_garbarges.top();
		s_garbarges.pop();
	}
}

std::string& util::replace_once(std::string& str,const std::string& old_value,const std::string& new_value)   
{   
	unsigned int pos=0;
	if( (pos=str.find(old_value,pos)) != std::string::npos )   
		str.replace(pos,old_value.length(),new_value);   

	return str;   
}   